pid_get_parent: fix for OpenBSD
authorAntoine Jacoutot <ajacoutot@gnome.org>
Mon, 13 May 2019 18:47:46 +0000 (20:47 +0200)
committerAntoine Jacoutot <ajacoutot@gnome.org>
Mon, 13 May 2019 18:47:46 +0000 (20:47 +0200)
This fixes a long standing bug in pid_get_parent on OpenBSD (which was mine
so... my fault). kp wasn't properly allocated and the function could return
random failures.

gtk/gtkmountoperation-x11.c

index 345570c3010075d6f301859de9b2d5e48e3c5616..1b7bff6aa1c8cc7202edbfc57b91bb874a4a1498 100644 (file)
@@ -736,7 +736,7 @@ pid_get_command_line (GPid pid)
 static GPid
 pid_get_parent (GPid pid)
 {
-  struct kinfo_proc kp;
+  struct kinfo_proc *kp;
   size_t len;
   GPid ppid;
 
@@ -747,11 +747,14 @@ pid_get_parent (GPid pid)
       return (-1);
   mib[5] = (len / sizeof(struct kinfo_proc));
 
-  if (sysctl (mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0)
+  kp = g_malloc0 (len);
+
+  if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
       return -1;
 
-  ppid = kp.p_ppid;
+  ppid = kp->p_ppid;
 
+  g_free (kp);
   return ppid;
 }